import uniRequest from 'uni-request';
import store from '@/store/index.js'

uniRequest.defaults.baseURL = 'http://113.31.109.223:8000';
uniRequest.defaults.headers.common['Authorization'] = uni.getStorageSync('token');

uniRequest.defaults.headers.post['Content-Type'] = 'application/json';

// 请求拦截
uniRequest.interceptors.request.use(
	request => {
		// if(uni.getStorageSync('token')){
		// 	request.defaults.headers.common['Authorization']=uni.getStorageSync('token');
		// }
		console.log('请求成功');
		store.state.isLoading=true
		//配置基本信息	
		return request;
	},
	err => {
		console.log('请求失败');
		return Promise.reject(err);
	});

// 响应拦截
uniRequest.interceptors.response.use(function(response) {
	console.log('返回进入拦截成功')
	store.state.isLoading=false
	// if(response.data.code=="1002"){
	// 	uni.removeStorage({
	// 	    key:'token',
	// 	    success: function(res){
	// 	        console.log('删除成功')
	// 	    }
	// 	})
	// }
	return Promise.resolve(response);
}, function(error) {
	console.log('返回进入拦截失败')
	return Promise.reject(error);
});

export default uniRequest;